package engine.systems.spatial.spatialToMouse
{
	import engine.classes.enumerations.Axis;
	import engine.classes.enumerations.SystemPriority;
	import engine.systems.update.GameSystem;
	
	/**
	 * The Spatial To Mouse System finds the (x, y) position of the mouse in a given Display Object and
	 * positions its Spatial there. If Spatial To Mouse is locked, then other systems and updates are free
	 * to move the Entity's Spatial.
	 */
	public class SpatialToMouseSystem extends GameSystem
	{
		public function SpatialToMouseSystem()
		{
			super(SpatialToMouseNode, updateNode);
			
			this.priority = SystemPriority.UPDATE;
		}
		
		private function updateNode(node:SpatialToMouseNode, time:Number):void
		{
			if(node.mouse.locked) return;
			
			switch(node.mouse.axis)
			{
				case Axis.X:
					node.spatial.x = node.mouse.container.mouseX;
					break;
				
				case Axis.Y:
					node.spatial.y = node.mouse.container.mouseY;
					break;
				
				case Axis.BOTH:
					node.spatial.x = node.mouse.container.mouseX;
					node.spatial.y = node.mouse.container.mouseY;
					break;
			}
			
			
		}
	}
}